package com.cool.service.impl;

import com.cool.mapper.UserMapper;
import com.cool.service.UserService;
import com.cool.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public void registe(UserVO userVO) {

        userVO.setGen_time(new Timestamp(System.currentTimeMillis()));
        userVO.setLast_login_time(new Timestamp(System.currentTimeMillis()));
        userMapper.insert(userVO);
    }

    @Override
    public UserVO login(UserVO userVO) {
        UserVO reUserVO = userMapper.selectOne(userVO);

        if(reUserVO == null){
            registe(userVO);
        }
        return reUserVO;
    }

    @Override
    public UserVO getUserVO(UserVO userVO) {
        UserVO reUserVO = userMapper.selectOne(userVO);
        return reUserVO;
    }

    @Override
    public void updateUserVO(UserVO userVO) {
        userMapper.updateByPrimaryKey(userVO);
    }
}
